#ifndef __MeshSerializer_H__
#define __MeshSerializer_H__


#include "video/Material.h"
#include "video/Mesh.h"
#include "video/SubMesh.h"
#include "video/Skeleton.h"
#include "video/MeshAnimation.h"
#include <vector>
#include <string>
#include <fstream>
#include <iomanip>

namespace KEngine
{

class Terrain;
class TextureManager;
class Device;
class MeshSerializer
{
public:
	
	MeshSerializer();
	virtual ~MeshSerializer();

	bool loadMesh(const char* filename, Mesh* mesh);
	bool loadMeshAnimation(const char* filename, MeshAnimation* meshAnim);

	void setTextureManagr(TextureManager* mgr)
	{
		mTextureMgr = mgr;
	}
protected:
	void importGlobalInfo();
	void importMaterialList();
	void importMaterial(Material* mtl);
	void importGeomObject();
	void importMesh(SubMesh* subMesh);
	void importSkin(SubMesh* subMesh, int face, int idx);
	void importHelperObject();

	void importGeomObjectAnim(MeshAnimation* meshAnim);
	void importMeshAnimation(SubMeshAnimation* subMeshAnim);
	void importMeshFrame(SubMeshAnimation* subMeshAnim);
	
protected:
	MaterialList		mCachedMtlList;
	SubMeshList			mCachedSubMeshList;
	HelperObjectList	mCachedHelperObjList;
	
	std::ifstream		infile;
	std::string			token;
	std::string			dir;

	TextureManager* mTextureMgr;
};

}

#endif //